def welcome():
    print('_'*20)
    print('欢迎登录学员管理系统')
    print('1:添加学员')
    print('2:删除学员')
    print('3:修改学员')
    print('4:查询学员信息')
    print('5:显示所有学员信息')
    print('6:退出系统')
    print('-'*20)

def add_info():
    print('-------添加学员-------')
    new_id=input('请输入学号:')
    new_name = input('请输入姓名:')
    new_tel = input('请输入电话:')
    for e in info:
        if e['id']==new_id or e['name']==new_name:
            print('该学员已存在')
            return
    dict1={}
    dict1['id']=new_id
    dict1['name']=new_name
    dict1['tel']=new_tel
    info.append(dict1)
    print(f'添加学员成功！学员信息如下：{info}')

def del_info():
    print('-------删除学员-------')
    del_name = input('请输入姓名:')
    for e in info:
        if e['name'] == del_name :
            info.remove(e)
            print('删除成功')
            break
      #else 和 for 配对 是在循环正常结束之后执行的，
      #若循环不正常结束(例如break)，else不会执行
    else:
       print('该学员不存在')
    print(info)
def up_info():
    print('-------修改学员-------')
    up_name=input('请输入要修改的学员姓名:')
    for e in  info:
       if e['name']==up_name:
          a=input('请输入新的手机号')
          e['tel']=a
          print('修改成功')
          break

    else:
      print('该学员不存在')
    print(info)

def sel_info():
    print('-------查询学员-------')
    sel_name = input('请输入要查询的学员姓名:')
    for e in info:
        if e['name']==sel_name:
            print(e)
            break
    else:
        print('该学员不存在')
def xian_info():
    print('-------查询所有学员信息-------')
    for e in info:
        print(e)



info=[]




while True:
    welcome()
    choose=input('请选择您需要的功能序号：')
    if choose=='1':
        add_info()
    elif choose=='2':
        del_info()
    elif choose=='3':
        up_info()
    elif choose=='4':
        sel_info()
    elif choose=='5':
        xian_info()
    elif choose=='6':
        flag = input('确定你要退出吗, yes or no:')
        if flag=='yes':
            break
    else:
        print('输入有误请重新选择')
